
#include "nx_api.h"

#ifdef __PRODUCT_NETXDUO__

#include "netx_mdns_test.h"

/* Frame (76 bytes) */
static const unsigned char pkt1_1[76] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb, 0xec, 0x17, /* ..^..... */
0x2f, 0xbd, 0xa4, 0xb1, 0x08, 0x00, 0x45, 0x00, /* /.....E. */
0x00, 0x3e, 0x01, 0x16, 0x00, 0x00, 0xff, 0x11, /* .>...... */
0x11, 0xeb, 0xc0, 0xa8, 0x07, 0x0a, 0xe0, 0x00, /* ........ */
0x00, 0xfb, 0x14, 0xe9, 0x14, 0xe9, 0x00, 0x2a, /* .......* */
0x26, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* &/...... */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x5f, /* ......._ */
0x68, 0x74, 0x74, 0x70, 0x04, 0x5f, 0x74, 0x63, /* http._tc */
0x70, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, /* p.local. */
0x00, 0x0c, 0x00, 0x01                          /* .... */
};

/* Frame (398 bytes) */
static const unsigned char pkt1_2[398] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb, 0x00, 0x11, /* ..^..... */
0x22, 0x33, 0x44, 0x57, 0x08, 0x00, 0x45, 0x00, /* "3DW..E. */
0x01, 0x80, 0x00, 0x07, 0x40, 0x00, 0xff, 0x11, /* ....@... */
0x8f, 0x28, 0x0a, 0x00, 0x00, 0x42, 0xe0, 0x00, /* .(...B.. */
0x00, 0xfb, 0x14, 0xe9, 0x14, 0xe9, 0x01, 0x6c, /* .......l */
0xbf, 0xcd, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x05, 0x5f, /* ......._ */
0x68, 0x74, 0x74, 0x70, 0x04, 0x5f, 0x74, 0x63, /* http._tc */
0x70, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, /* p.local. */
0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x64, /* .......d */
0x00, 0x1e, 0x0b, 0x41, 0x52, 0x4d, 0x4d, 0x44, /* ...ARMMD */
0x4e, 0x53, 0x54, 0x65, 0x73, 0x74, 0x05, 0x5f, /* NSTest._ */
0x68, 0x74, 0x74, 0x70, 0x04, 0x5f, 0x74, 0x63, /* http._tc */
0x70, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, /* p.local. */
0x0b, 0x41, 0x52, 0x4d, 0x4d, 0x44, 0x4e, 0x53, /* .ARMMDNS */
0x54, 0x65, 0x73, 0x74, 0x05, 0x6c, 0x6f, 0x63, /* Test.loc */
0x61, 0x6c, 0x00, 0x00, 0x01, 0x80, 0x01, 0x00, /* al...... */
0x00, 0x00, 0x78, 0x00, 0x04, 0x0a, 0x00, 0x00, /* ..x..... */
0x42, 0x0b, 0x41, 0x52, 0x4d, 0x4d, 0x44, 0x4e, /* B.ARMMDN */
0x53, 0x54, 0x65, 0x73, 0x74, 0x05, 0x6c, 0x6f, /* STest.lo */
0x63, 0x61, 0x6c, 0x00, 0x00, 0x2f, 0x80, 0x01, /* cal../.. */
0x00, 0x00, 0x00, 0x78, 0x00, 0x16, 0x0b, 0x41, /* ...x...A */
0x52, 0x4d, 0x4d, 0x44, 0x4e, 0x53, 0x54, 0x65, /* RMMDNSTe */
0x73, 0x74, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, /* st.local */
0x00, 0x00, 0x01, 0x40, 0x0b, 0x41, 0x52, 0x4d, /* ...@.ARM */
0x4d, 0x44, 0x4e, 0x53, 0x54, 0x65, 0x73, 0x74, /* MDNSTest */
0x05, 0x5f, 0x68, 0x74, 0x74, 0x70, 0x04, 0x5f, /* ._http._ */
0x74, 0x63, 0x70, 0x05, 0x6c, 0x6f, 0x63, 0x61, /* tcp.loca */
0x6c, 0x00, 0x00, 0x21, 0x80, 0x01, 0x00, 0x00, /* l..!.... */
0x00, 0x64, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, /* .d...... */
0x00, 0x50, 0x0b, 0x41, 0x52, 0x4d, 0x4d, 0x44, /* .P.ARMMD */
0x4e, 0x53, 0x54, 0x65, 0x73, 0x74, 0x05, 0x6c, /* NSTest.l */
0x6f, 0x63, 0x61, 0x6c, 0x00, 0x0b, 0x41, 0x52, /* ocal..AR */
0x4d, 0x4d, 0x44, 0x4e, 0x53, 0x54, 0x65, 0x73, /* MMDNSTes */
0x74, 0x05, 0x5f, 0x68, 0x74, 0x74, 0x70, 0x04, /* t._http. */
0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, 0x6f, 0x63, /* _tcp.loc */
0x61, 0x6c, 0x00, 0x00, 0x10, 0x80, 0x01, 0x00, /* al...... */
0x00, 0x00, 0x64, 0x00, 0x14, 0x08, 0x70, 0x61, /* ..d...pa */
0x70, 0x65, 0x72, 0x3d, 0x41, 0x34, 0x0a, 0x76, /* per=A4.v */
0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x30, /* ersion=0 */
0x31, 0x0b, 0x41, 0x52, 0x4d, 0x4d, 0x44, 0x4e, /* 1.ARMMDN */
0x53, 0x54, 0x65, 0x73, 0x74, 0x05, 0x5f, 0x68, /* STest._h */
0x74, 0x74, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, /* ttp._tcp */
0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, /* .local.. */
0x2f, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, /* /.....x. */
0x25, 0x0b, 0x41, 0x52, 0x4d, 0x4d, 0x44, 0x4e, /* %.ARMMDN */
0x53, 0x54, 0x65, 0x73, 0x74, 0x05, 0x5f, 0x68, /* STest._h */
0x74, 0x74, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, /* ttp._tcp */
0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, /* .local.. */
0x05, 0x00, 0x00, 0x80, 0x00, 0x40              /* .....@ */
};

/* Frame (269 bytes) */
static const unsigned char pkt2_1[269] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb, 0x00, 0x11, /* ..^..... */
0x22, 0x33, 0x44, 0x57, 0x08, 0x00, 0x45, 0x00, /* "3DW..E. */
0x00, 0xff, 0x00, 0x01, 0x40, 0x00, 0xff, 0x11, /* ....@... */
0x8f, 0xaf, 0x0a, 0x00, 0x00, 0x42, 0xe0, 0x00, /* .....B.. */
0x00, 0xfb, 0x14, 0xe9, 0x14, 0xe9, 0x00, 0xeb, /* ........ */
0x13, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, /* .%...... */
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0b, 0x41, /* .......A */
0x52, 0x4d, 0x4d, 0x44, 0x4e, 0x53, 0x54, 0x65, /* RMMDNSTe */
0x73, 0x74, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, /* st.local */
0x00, 0x00, 0xff, 0x00, 0x01, 0x0b, 0x41, 0x52, /* ......AR */
0x4d, 0x4d, 0x44, 0x4e, 0x53, 0x54, 0x65, 0x73, /* MMDNSTes */
0x74, 0x05, 0x5f, 0x68, 0x74, 0x74, 0x70, 0x04, /* t._http. */
0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, 0x6f, 0x63, /* _tcp.loc */
0x61, 0x6c, 0x00, 0x00, 0xff, 0x00, 0x01, 0x0b, /* al...... */
0x41, 0x52, 0x4d, 0x4d, 0x44, 0x4e, 0x53, 0x54, /* ARMMDNST */
0x65, 0x73, 0x74, 0x05, 0x6c, 0x6f, 0x63, 0x61, /* est.loca */
0x6c, 0x00, 0x00, 0x01, 0x80, 0x01, 0x00, 0x00, /* l....... */
0x00, 0x78, 0x00, 0x04, 0x0a, 0x00, 0x00, 0x42, /* .x.....B */
0x0b, 0x41, 0x52, 0x4d, 0x4d, 0x44, 0x4e, 0x53, /* .ARMMDNS */
0x54, 0x65, 0x73, 0x74, 0x05, 0x5f, 0x68, 0x74, /* Test._ht */
0x74, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, /* tp._tcp. */
0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x21, /* local..! */
0x80, 0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x19, /* .....d.. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x0b, 0x41, /* .....P.A */
0x52, 0x4d, 0x4d, 0x44, 0x4e, 0x53, 0x54, 0x65, /* RMMDNSTe */
0x73, 0x74, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, /* st.local */
0x00, 0x0b, 0x41, 0x52, 0x4d, 0x4d, 0x44, 0x4e, /* ..ARMMDN */
0x53, 0x54, 0x65, 0x73, 0x74, 0x05, 0x5f, 0x68, /* STest._h */
0x74, 0x74, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, /* ttp._tcp */
0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, /* .local.. */
0x10, 0x80, 0x01, 0x00, 0x00, 0x00, 0x64, 0x00, /* ......d. */
0x14, 0x08, 0x70, 0x61, 0x70, 0x65, 0x72, 0x3d, /* ..paper= */
0x41, 0x34, 0x0a, 0x76, 0x65, 0x72, 0x73, 0x69, /* A4.versi */
0x6f, 0x6e, 0x3d, 0x30, 0x31                    /* on=01 */
};

/* Frame (94 bytes) */
static const unsigned char pkt2_16[94] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb, 0xec, 0x17, /* ..^..... */
0x2f, 0xbd, 0xa4, 0xb1, 0x08, 0x00, 0x45, 0x00, /* /.....E. */
0x00, 0x50, 0x01, 0x2e, 0x00, 0x00, 0xff, 0x11, /* .P...... */
0x11, 0xc1, 0xc0, 0xa8, 0x07, 0x0a, 0xe0, 0x00, /* ........ */
0x00, 0xfb, 0x14, 0xe9, 0x14, 0xe9, 0x00, 0x3c, /* .......< */
0xa4, 0xd7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x41, /* .......A */
0x52, 0x4d, 0x4d, 0x44, 0x4e, 0x53, 0x54, 0x65, /* RMMDNSTe */
0x73, 0x74, 0x05, 0x5f, 0x68, 0x74, 0x74, 0x70, /* st._http */
0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, 0x6f, /* ._tcp.lo */
0x63, 0x61, 0x6c, 0x00, 0x00, 0x21, 0x00, 0x01, /* cal..!.. */
0xc0, 0x0c, 0x00, 0x10, 0x00, 0x01              /* ...... */
};

/* Frame (340 bytes) */
static const unsigned char pkt2_17[340] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb, 0x00, 0x11, /* ..^..... */
0x22, 0x33, 0x44, 0x57, 0x08, 0x00, 0x45, 0x00, /* "3DW..E. */
0x01, 0x46, 0x00, 0x07, 0x40, 0x00, 0xff, 0x11, /* .F..@... */
0x8f, 0x62, 0x0a, 0x00, 0x00, 0x42, 0xe0, 0x00, /* .b...B.. */
0x00, 0xfb, 0x14, 0xe9, 0x14, 0xe9, 0x01, 0x32, /* .......2 */
0xa4, 0x76, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, /* .v...... */
0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x0b, 0x41, /* .......A */
0x52, 0x4d, 0x4d, 0x44, 0x4e, 0x53, 0x54, 0x65, /* RMMDNSTe */
0x73, 0x74, 0x05, 0x5f, 0x68, 0x74, 0x74, 0x70, /* st._http */
0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, 0x6f, /* ._tcp.lo */
0x63, 0x61, 0x6c, 0x00, 0x00, 0x21, 0x80, 0x01, /* cal..!.. */
0x00, 0x00, 0x00, 0x64, 0x00, 0x19, 0x00, 0x00, /* ...d.... */
0x00, 0x00, 0x00, 0x50, 0x0b, 0x41, 0x52, 0x4d, /* ...P.ARM */
0x4d, 0x44, 0x4e, 0x53, 0x54, 0x65, 0x73, 0x74, /* MDNSTest */
0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x0b, /* .local.. */
0x41, 0x52, 0x4d, 0x4d, 0x44, 0x4e, 0x53, 0x54, /* ARMMDNST */
0x65, 0x73, 0x74, 0x05, 0x5f, 0x68, 0x74, 0x74, /* est._htt */
0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, /* p._tcp.l */
0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x10, 0x80, /* ocal.... */
0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x14, 0x08, /* ....d... */
0x70, 0x61, 0x70, 0x65, 0x72, 0x3d, 0x41, 0x34, /* paper=A4 */
0x0a, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, /* .version */
0x3d, 0x30, 0x31, 0x0b, 0x41, 0x52, 0x4d, 0x4d, /* =01.ARMM */
0x44, 0x4e, 0x53, 0x54, 0x65, 0x73, 0x74, 0x05, /* DNSTest. */
0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x01, /* local... */
0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x04, /* .....x.. */
0x0a, 0x00, 0x00, 0x42, 0x0b, 0x41, 0x52, 0x4d, /* ...B.ARM */
0x4d, 0x44, 0x4e, 0x53, 0x54, 0x65, 0x73, 0x74, /* MDNSTest */
0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, /* .local.. */
0x2f, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, /* /.....x. */
0x16, 0x0b, 0x41, 0x52, 0x4d, 0x4d, 0x44, 0x4e, /* ..ARMMDN */
0x53, 0x54, 0x65, 0x73, 0x74, 0x05, 0x6c, 0x6f, /* STest.lo */
0x63, 0x61, 0x6c, 0x00, 0x00, 0x01, 0x40, 0x0b, /* cal...@. */
0x41, 0x52, 0x4d, 0x4d, 0x44, 0x4e, 0x53, 0x54, /* ARMMDNST */
0x65, 0x73, 0x74, 0x05, 0x5f, 0x68, 0x74, 0x74, /* est._htt */
0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, /* p._tcp.l */
0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x2f, 0x80, /* ocal../. */
0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x25, 0x0b, /* ....x.%. */
0x41, 0x52, 0x4d, 0x4d, 0x44, 0x4e, 0x53, 0x54, /* ARMMDNST */
0x65, 0x73, 0x74, 0x05, 0x5f, 0x68, 0x74, 0x74, /* est._htt */
0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, /* p._tcp.l */
0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x05, 0x00, /* ocal.... */
0x00, 0x80, 0x00, 0x40                          /* ...@ */
};

static MDNS_SERVICE mdns_service = {"ARMMDNSTest", "_http._tcp", NX_NULL, "paper=A4;version=01", 100, 0, 0, 80, NX_MDNS_RR_SET_UNIQUE, 0};

MDNS_TEST_SEQ mdns_response_interval[] = {
    {TITLE, "Response interval", 17, 0},

    /* Add service. */
    {MDNS_SERVICE_ADD, (char*)&mdns_service, 0, 0},
    {WAIT, NX_NULL, 0, 5},
    {DUMP, NX_NULL, 0, 0},


    /* Reset timer. */
    {MDNS_TIMER_RESET, NX_NULL, 0, 0},

    /* Inject a query. */
    {INJECT, (char*)&pkt1_1[0], sizeof(pkt1_1), 0},

    /* Check the response. */
    {MDNS_CHECK_DATA_V4, (char*)&pkt1_2[0], sizeof(pkt1_2), 1},

    /* Check timer in range 20~120ms. */
    {MDNS_TIMER_CHECK, NX_NULL, 5, 7},

    /* Wait 5 seconds. */
    {WAIT, NX_NULL, 0, 5},
    {DUMP, NX_NULL, 0, 0},

    /* Reset timer. */
    {MDNS_TIMER_RESET, NX_NULL, 0, 0},

    /* Inject a query. */
    {INJECT, (char*)&pkt1_1[0], sizeof(pkt1_1), 0},

    /* Check the response. */
    {MDNS_CHECK_DATA_V4, (char*)&pkt1_2[0], sizeof(pkt1_2), 1},

    /* Check timer in range 20~120ms. */
    {MDNS_TIMER_CHECK, NX_NULL, 5, 7},

    /* Reset timer. */
    {MDNS_TIMER_RESET, NX_NULL, 0, 0},

    /* Inject a query immediately. */
    {INJECT, (char*)&pkt1_1[0], sizeof(pkt1_1), 0},

    /* It MUST NOT answer in one second. */
    /* Check the response. */
    {MDNS_CHECK_DATA_V4, (char*)&pkt1_2[0], sizeof(pkt1_2), 2},

    /* Check timer in range 1s~. */
    {MDNS_TIMER_CHECK, NX_NULL, 100, 200},

    /* Wait 5 seconds. */
    {WAIT, NX_NULL, 0, 5},
    {DUMP, NX_NULL, 0, 0},

    /* Reset timer. */
    {MDNS_TIMER_RESET, NX_NULL, 0, 0},

    /* Inject a query. */
    {INJECT, (char*)&pkt1_1[0], sizeof(pkt1_1), 0},

    /* Check the response. */
    {MDNS_CHECK_DATA_V4, (char*)&pkt1_2[0], sizeof(pkt1_2), 1},

    /* Check timer in range 20~120ms. */
    {MDNS_TIMER_CHECK, NX_NULL, 5, 7},
        

    /* Reset timer. */
    {MDNS_TIMER_RESET, NX_NULL, 0, 0},

    /* Inject a query. */
    {INJECT, (char*)&pkt2_16[0], sizeof(pkt2_16), 0},

    /* Check the response. */
    {MDNS_CHECK_DATA_V4, (char*)&pkt2_17[0], sizeof(pkt2_17), 1},

    /* Check timer in range 0~10ms. Resonable error is 30ms. */
    {MDNS_TIMER_MAX_CHECK, NX_NULL, 0, 1 + 3},

    /* Reset timer. */
    {MDNS_TIMER_RESET, NX_NULL, 0, 0},

    /* Inject a probing immediately. */
    {INJECT, (char*)&pkt2_1[0], sizeof(pkt2_1), 0},

    /* It MUST answer at least 250ms. */
    /* Check the response. */
    {MDNS_CHECK_DATA_V4, (char*)&pkt2_17[0], sizeof(pkt2_17), 1},

    /* Check timer in range 250~. */
    {MDNS_TIMER_CHECK, NX_NULL, 75, 100},
};

int mdns_response_interval_size = sizeof(mdns_response_interval) / sizeof(MDNS_TEST_SEQ);

#endif /* __PRODUCT_NETXDUO__  */

